package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.employee.ResetPwdRequest;
import com.mes.cloud.api.dto.request.employee.UpdatePwdRequest;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.entity.LoginParamRequest;
import com.mes.cloud.entity.LoginUser;
import com.mes.cloud.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author Mr.zhang
 * @description
 * @email zhangchao4@shinho.net.cn
 * @date 2019/11/28 15:02
 **/
@RestController
@RequestMapping(value = "/user")
@Api(tags = "用户登录", description = "用户登录相关接口", value = "用户登录")
public class LoginController {

    private LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @ApiOperation(value = "用户登录", notes = "用户登录", response = LoginUser.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "username", value = "用户名", required = true),
            @ApiImplicitParam(name = "password", value = "密码", required = true)})
    @PostMapping("/login")
    public JsonResult<LoginUser> login(@Valid @RequestBody LoginParamRequest loginParamRequest) {
        return loginService.login(loginParamRequest);
    }

    @ApiOperation(value = "用户退出", notes = "用户退出")
    @PostMapping("/logout/{platform}")
    public JsonResult logout(HttpServletRequest request, @PathVariable("platform") String platform) {
        return loginService.logout(request,platform);
    }


    @ApiOperation(value = "获取私钥", notes = "获取私钥")
    @GetMapping("/get/{employeeNo}")
    public JsonResult get(@PathVariable String employeeNo) {
        return loginService.get(employeeNo);
    }

    @ApiOperation(value = "重置密码", notes = "重置密码")
    @PostMapping("/resetPwd")
    public JsonResult resetPwd(@Valid @RequestBody ResetPwdRequest resetPwdRequest) {
        return loginService.resetPwd(resetPwdRequest);
    }

    @ApiOperation(value = "修改密码", notes = "修改密码")
    @PostMapping("/updatePwd")
    public JsonResult updatePwd(@Valid @RequestBody UpdatePwdRequest updatePwdRequest) {
        return loginService.updatePwd(updatePwdRequest);
    }


}

